from pyodm.criteria import Criteria

class BaseField(object):
    def __init__(self, value=None, unique=False, index=False):
        self._value = value
        self._unique = unique
        self._index = index

    def is_unique(self):
        return self._unique

    def is_index(self):
        return self._index

    def get_value(self):
        return self._value

    def set_value(self, value):
        self._value = value

class IntegerField(BaseField):
    pass

class StringField(BaseField):
    pass

class DateField(BaseField):
    pass

class BoolField(BaseField):
    pass

class ForeignKeyField(BaseField):
    pass

class ReferenceField(object):
    def __init__(self, doccls, parent=None, attrname=None):
        self.doccls = doccls
        self.parent = parent
        self.name = attrname
    
    def getReferredClass(self):
        return self.doccls
    
    def add(self, document):
        document.setForeignKey(self.parent.getName(), self.name, self.parent.getKey())
        
    def getByKey(self, key):
        return self.doccls.getByKey(key)
        
    def get(self, criterias=[]):
        criteria = Criteria(self.parent.getName() + "_" + self.name, "=", self.parent.getKey())
        criterias.append(criteria)
        return self.doccls.get(criterias)
